import Operator from "./Operator";
import { RC } from "../config/RC";
import Group from "../entities/Group";

class CreateGroupObjectOperator extends Operator {
    public async execute(): Promise<RC> {
        try {
            let groupName: string = this.args.getProperty("groupName");
            if (groupName === '' || groupName === null || groupName === undefined) {
                console.log(3);
                return RC.INVALID_ARGUMENT;
            }
            const groupId = this.args.getProperty("generateId");
            this.args.setProperty("groupId", groupId);
            const group = new Group(groupId, groupName); // 创建一个Group对象
            await group.insertNewGroup();  // 插入数据库

            this.args.setProperty("GroupObj", group);
            return RC.SUCCESS;
        } catch (error) {
            // 处理异常情况
            console.error('Error creating group object:', error);
            return RC.INTERNAL_ERROR;
        }

    }
}

export default CreateGroupObjectOperator;